/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gesturetracking;

import com.primesense.NITE.HandEventArgs;
import java.awt.*;
import java.util.ArrayList;
import javax.swing.JPanel;
import nite.gestures.AbstractGesture.PrimaryPointUpdateObserver;
import org.OpenNI.IObservable;
import org.OpenNI.IObserver;
import org.OpenNI.Point3D;

/**
 *
 * @author xvanek9
 */
public class CursorPanel extends JPanel {
    
    Label lbl;

    public Label getLbl() {
        return lbl;
    }
    Point cursor;
    public ArrayList<PrimaryPointUpdateObserver> observers;
    public ArrayList<PrimaryPointUpdateObserver> getObservers() {
        return observers;
    }
    
    public CursorPanel(){
        this.setSize(640, 480);
        lbl = new Label();
        //lbl.setSize(200, 50);
        lbl.setBounds(20, 20, 200, 200);
        Font f = new Font("Arial",15,18);
        lbl.setFont(f);
        lbl.setText("init");
        this.add(lbl);
        observers = new ArrayList<PrimaryPointUpdateObserver>();
    }
    
    public void updateLabel(){
        for (PrimaryPointUpdateObserver obs : observers){
            obs.getPosition();
            lbl.setText(String.valueOf(obs.getPosition().getX())+", " + String.valueOf(obs.getPosition().getX()));
            paintCursor(obs.getPosition());
        }
    }
    
    @Override
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        g.setColor(Color.pink);
        //g.fillRect(x, y, 15, 35);
        //g.drawOval(x, y, 10, 10);
        g.fillOval(x, y, 15,15);
    }
    
    int x,y;
            
            public void paintCursor(Point3D points){
            
//        this.paint(this.getGraphics().create( (int) points.getX(), (int) points.getY(), WIDTH, WIDTH));
//        this.repaint();
//        cursor = new Point();
//        int x;
        if (points.getX() < 0){
            x = (int) ((int) -points.getX()/3.75) + 320;
        }else{
            x = (int) ((int) points.getX()/3.75);
        }
        //y = (int) (points.getY()-300);
        y = (int) (points.getY()/1.375) - 300;
//        
//        cursor.setLocation(x, (int) (points.getY()-300));
//        
//        Cursor c = new Cursor(3);
//        
//        this.setCursor(c);
        paintComponent(this.getGraphics());
    }
}
